#include "btform.h"
#include "ui_btform.h"
#include <QDebug>

BtForm::BtForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BtForm)
{
    ui->setupUi(this);

    ui->lineBox->hide();
    // 设置line1的动画效果
    line1Animal = new QPropertyAnimation(ui->line1, "geometry", this);
    line1Animal->setDuration(1500);
    line1Animal->setKeyValueAt(0, QRect(2, 15, 3, 0));
    line1Animal->setKeyValueAt(0.5, QRect(2, 0, 3, 15));
    line1Animal->setKeyValueAt(1, QRect(2, 15, 3, 0));
    line1Animal->setLoopCount(-1);
    line1Animal->start();
    // 设置line2的动画效果
    line2Animal = new QPropertyAnimation(ui->line2, "geometry", this);
    line2Animal->setDuration(1600);
    line2Animal->setKeyValueAt(0, QRect(12, 15, 3, 0));
    line2Animal->setKeyValueAt(0.5, QRect(12, 0, 3, 15));
    line2Animal->setKeyValueAt(1, QRect(12, 15, 3, 0));
    line2Animal->setLoopCount(-1);
    line2Animal->start();
    // 设置line3的动画效果
    line3Animal = new QPropertyAnimation(ui->line3, "geometry", this);
    line3Animal->setDuration(1700);
    line3Animal->setKeyValueAt(0, QRect(22, 15, 3, 0));
    line3Animal->setKeyValueAt(0.5, QRect(22, 0, 3, 15));
    line3Animal->setKeyValueAt(1, QRect(22, 15, 3, 0));
    line3Animal->setLoopCount(-1);
    line3Animal->start();
    // 设置line4的动画效果
    line4Animal = new QPropertyAnimation(ui->line4, "geometry", this);
    line4Animal->setDuration(1800);
    line4Animal->setKeyValueAt(0, QRect(32, 15, 3, 0));
    line4Animal->setKeyValueAt(0.5, QRect(32, 0, 3, 15));
    line4Animal->setKeyValueAt(1, QRect(32, 15, 3, 0));
    line4Animal->setLoopCount(-1);
    line4Animal->start();
}

BtForm::~BtForm()
{
    delete ui;
}

void BtForm::setIconAndText(const QString &btIcon, const QString &btText, int pageId)
{
    // 设置按钮图标
    ui->btIcon->setPixmap(QPixmap(btIcon));

    // 设置按钮文本
    ui->btText->setText(btText);

    // 设置miniMusic的按钮与pageId绑定起来
    this->pageId = pageId;
}

int BtForm::getPageId() const
{
    return pageId;
}

void BtForm::clearColor()
{
    ui->btStyle->setStyleSheet("#btStyle:hover{background-color:#D8D8D8;}");
    qDebug() << "clearColor";
}

void BtForm::showLineBox()
{
    ui->lineBox->show();
}

void BtForm::mousePressEvent(QMouseEvent *event)
{
    // 1.鼠标按下修改按钮颜色
    ui->btStyle->setStyleSheet("#btStyle{background-color:rgb(30, 206, 154);}");

    // 2.鼠标按下stackWidget切换对应page页面
    // 问题1：什么时机完成切换
    // 问题2：谁来完成切换
    // 问题3：切换时按钮和page的对应关系

    // 点击后发送信号给minimusic
    emit btClick(pageId);
}
